package com.example.javaeekeshe.mapper;

import com.example.javaeekeshe.pojo.GoodsAndGoodsCarBean;
import com.example.javaeekeshe.pojo.GoodsCarBean;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsCarMapper {
    /**
     * 加入购物车
     * @param goodsCarBean
     */
    @Insert("insert into goodscar (uid,gid,carcolor)values(#{uid},#{gid},#{carcolor})")
    void addCar (GoodsCarBean goodsCarBean);

    /**
     *
     * 根据用户id获取购物车商品
     * @param id
     * @return
     */
    @Select("SELECT goodscar.id,goods.id as gid,goods.`name`,goods.mainimg AS img,goodscar.carcolor AS color,goods.price,goods.gstate " +
            "FROM goodscar,goods WHERE goodscar.gid=goods.id AND goodscar.uid=#{id};")
    List<GoodsAndGoodsCarBean> selectGoodsCarByUid(Integer id);

    /**
     * 移出商品
     * @param id
     * @param uid
     */
    @Delete("delete from goodscar where id=#{id} and uid= #{uid}")
    void delById(Integer id,Integer uid);


    @Select("SELECT goodscar.id,goods.id as gid,goods.`name`,goods.mainimg AS img,goodscar.carcolor AS color,goods.price,goods.gstate " +
            "FROM goodscar,goods WHERE goodscar.gid=goods.id AND  goodscar.id=#{id}")
    GoodsAndGoodsCarBean selectGoodsCarById(Integer id);
}
